
package ipark.gui.mapeditor;

import java.awt.*;
import java.io.Serializable;
import javax.swing.ImageIcon;

/**
 * Basic class for all components
 * @author jernej
 */
public abstract class MapComponent extends Component implements Serializable{
  
    private double mWidth,mHeight;
    private double metersPerPixel = 0.04;
    private boolean isEntry = false;
    
  /**
   * function, which returns representing class of this component
   * @param iWidth      wanted width of an image
   * @param iHeight     wanted height of an image
   * @return    representing image, with wanted size
   */
  public abstract ImageIcon getIcon(int iWidth, int iHeight);
  
  /**
   * setter for ratio between pixel and meter for internal calculations
   * @param mpp meters per pixel
   */
  public void setMetersPerPixel(double mpp){
      metersPerPixel = mpp;
  }
  
  /**
   * getter for ratio between pixel and meter
   * @return
   */
  protected double getMetersPerPixel(){
      return metersPerPixel;
  }
  
  /**
   * load images for component - useful when we deserialize object
   */
  public abstract void loadImages();
  
  /**
   * is component horizontal resizable?
   * @return true, if it is, else false
   */
  public abstract boolean isHorizontalResizable();
  
  /**
   * is component vertical resizable?
   * @return true, if it is, else false
   */
  public abstract boolean isVerticalResizable();
  
  /**
   * is component diagonal resizable?
   * @return true, if it is, else false
   */
  public abstract boolean isDiagonalResizable();
  
  /**
   * return minimum height
   * @return minimum height
   */
  public abstract double minHeightMeters();
  
  /**
   * return minimum width
   * @return minimum width
   */
  public abstract double minWidthMeters();
  
  /**
   * get current width
   * @return current width in meters
   */
  public double getWidthMeters(){
      return mWidth;
  }
  
  /**
   * set current width in meters
   * @param width new width
   */
  public void setWidthMeters(double width){
      mWidth = width;
  }
  
  /**
   * get component height in meters
   * @return current height
   */
  public double getHeightMeters(){
      return mHeight;
  }
  
  /**
   * set new height in meters
   * @param height new height
   */
  public void setHeightMeters(double height){
      mHeight = height;
  }
  
  /**
   * tell us, if is this entry point for car
   * @return true if it is, else false
   */
  public boolean isEntryVertex(){
      return isEntry;
  }
  
  /**
   * set component to be entry point
   * @param entry is this entry?
   */
  public void setEntryVertex(boolean entry){
      isEntry = entry;
  }
  
  /**
   * return array of editable properties for property editor
   * @return array of property names
   */
  public abstract String[] getPropertyNames();
  
  /**
   * if this is property, which can have only few distinct values
   * return list of them, else return null
   * @param property property name, for which we want to get possible values
   * @return list of possible values
   */
  public abstract String[] getTypeNames(String property);
  
  /**
   * return the current property value
   * @param name property name
   * @return property value
   */
  public abstract Object getPropertyValue(String name);
  
  /**
   * function which try to change specific property to specific value
   * @param name    property name
   * @param value   new value
   * @return        true, if we changed property, else false
   */
  public abstract boolean setPropertyValue(String name, String value);
  
  /**
   * copy komponent itself
   * @return new object, which is copy of this object
   */
  public abstract MapComponent duplicate();
  
  /**
   * tells us, if is specified side joinable
   * @param side which side
   * @return true, if it is, else false
   */
  public abstract boolean jointSide(int side);

}
